<template>
  <div class="app-container">
    <div class="page-card top-tabs">
      <div class="page-back" @click="$router.back()">
        <i class="el-icon-arrow-left"></i>
        {{ $route.query.schoolName || "全部学校" }}
      </div>
      <el-tabs v-model="examSubjectId" @tab-click="examSubjectChange">
        <el-tab-pane
          v-for="item in tabList"
          :key="item.id"
          :label="item.name"
          :name="item.id.toString()"
        ></el-tab-pane>
      </el-tabs>
    </div>

    <div class="page-card m-top">
      <el-tabs v-model="activeTab" @tab-click="getList(null)">
        <el-tab-pane label="识别记录" name="sbjl"></el-tab-pane>
        <el-tab-pane label="未上传" name="wsc"></el-tab-pane>
        <el-tab-pane label="缺考名单" name="qkmd"></el-tab-pane>
        <el-tab-pane label="后传题卡" name="hctk"></el-tab-pane>
      </el-tabs>

      <component
        ref="component"
        v-if="xmxx.id && examSubjectId"
        :xmxx="xmxx"
        :examSchoolId="examSchoolId"
        :examSubjectId="examSubjectId"
        :is="activeTab"
        :kclb="kclb"
        :bjlb="bjlb"
      ></component>
    </div>
  </div>
</template>

<script>
import sbjl from "./components/sbjl.vue";
import wsc from "./components/wsc.vue";
import qkmd from "./components/qkmd.vue";
import hctk from "./components/hctk.vue";
import { scanExamSubject, scanQuestionCardSelect } from "@/api/xmgl/smgl";
import { classlist } from "@/api/xmgl/xsgl";
export default {
  name: "Project_smglxq",
  components: {
    sbjl: sbjl,
    wsc: wsc,
    qkmd: qkmd,
    hctk: hctk,
  },
  data() {
    return {
      firstLoad: true,

      xmxx: {},
      loading: false,
      examSubjectId: "",
      examSchoolId: "",
      activeTab: "sbjl",
      tabList: [],
      qbbjlb: [],
      kclb: [],
    };
  },
  computed: {
    bjlb() {
      return this.qbbjlb.filter((item) => {
        return item.schoolId == this.$route.query.examSchoolId;
      });
    },
  },
  created() {
    this.$store.dispatch("getXmxx").then((res) => {
      this.xmxx = res;

      this.examSubjectId = this.$route.query.examSubjectId;
      this.examSchoolId = this.$route.query.examSchoolId;
      this.initData();

      this.$nextTick(() => {
        this.getList();
      });
    });
  },
  activated() {
    if (!this.firstLoad) {
      if (this.$store.state.app.isRefresh) {
        this.examSubjectId = this.$route.query.examSubjectId;
        this.examSchoolId = this.$route.query.examSchoolId;
        this.$nextTick(() => {
          this.getList(1);
        });
      } else {
        this.getList();
      }
    }
    this.firstLoad = false;
    this.$store.dispatch("app/setIsRefresh", false);
  },
  methods: {
    initData() {
      scanExamSubject({
        examId: this.xmxx.id,
      }).then((res) => {
        this.tabList = res.data;
      });

      classlist({
        pageNum: 1,
        pageSize: 9999,
        examId: this.xmxx.id,
      }).then((res) => {
        this.qbbjlb = res.rows;
      });
      scanQuestionCardSelect({
        type: 2,
        examId: this.xmxx.id,
      }).then((res) => {
        this.kclb = res.data;
      });
    },
    examSubjectChange(tab) {
      this.examSubjectId = tab.name;
      this.getList(1);
    },
    getList(page = null) {
      this.$nextTick(() => {
        this.$refs.component.getList(page);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.top-tabs {
  display: flex;
  padding: 0;
  padding-right: 24px;

  .page-back {
    height: 54px;
    line-height: 54px;
    color: #ffffff;
    background: #1a48db;
    font-size: 14px;
    font-weight: bold;
    margin-right: 24px;
    padding: 0 10px;
    text-align: center;
    cursor: pointer;
    flex-shrink: 0;
  }

  .el-tabs {
      width: calc(100% - 80px);
  }
}
</style>